importScripts('./spark-md5.min.js');
importScripts('./util.js');

self.addEventListener('message',e=>{
    console.log('worker已收到,开始干活');
    let list=e.data;
    for (let i = 0; i < list.length; i++) {
        let o = list[i];
        let file = o.file;
        o.md5="计算中...";
        o.start=new Date().valueOf();
        getFileMd5(file, 1024 * 1024 * 10, function (per) {
            o.per = per;
            o.useTime = (new Date().valueOf() - o.start) / 1000;
            self.postMessage(list);
        }).then(md5Str => {
            o.md5 = md5Str;
            o.useTime = (new Date().valueOf() - o.start) / 1000;
            self.postMessage(list);
        });
    }
});